'use strict';
/**
 * Created by henian.xu on 2018/11/5.
 *
 */

const { Builder } = require('nuxt');

module.exports = app => {
  app.config.coreMiddleware.splice(0, 0, 'nuxtRender');
  app.beforeStart(async () => {
    try {
      // if (app.config.env === 'local') {
      const builder = new Builder(app.nuxt);
      await builder.build();
      // }
      // console.log('111', app.config.nuxt.dev, app.config.env);
      if (!app.config.nuxt.dev) {
        console.log('[nuxt] Building done'); // eslint-disable-line no-console
      }
    } catch (error) {
      console.log('[nuxt] Building error', error); // eslint-disable-line no-console
      process.exit(1);
    }
  });
};
